import Vue from 'vue';
import Router from 'vue-router';
const _import = require('./_import_' + process.env.NODE_ENV);
// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router);

/* Layout */
import Layout from '../views/layout/Layout';

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirct in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
**/
export const constantRouterMap = [
  { path: '/login', component: _import('login/index'), hidden: true },
  {
    path: '/authredirect',
    component: _import('login/authredirect'),
    hidden: true
  },
  { path: '/404', component: _import('errorPage/404'), hidden: true },
  { path: '/401', component: _import('errorPage/401'), hidden: true },
  {
    path: '',
    component: Layout,
    redirect: '/home',
    children: [
      {
        name: 'home',
        path: 'home',
        component: _import('home/index'),
        meta: { title: '首页', icon: 'dashboard', noCache: true }
      },
      {
        hidden: true,
        name: 'moreNews',
        path: 'more',
        component: _import('home/moreNews'),
        meta: { title: '新闻列表', icon: 'list', noCache: true }
      }
    ]
  }
];

export default new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
});

export const asyncRouterMap = [
  {
    path: '/reception',
    redirect: '/reception/',
    component: Layout,
    meta: { title: '业务受理', icon: 'list', permission: ['reception_index', 'reception_collect', 'reception_livingAllowancesDetail'] },
    children: [
      {
        path: '',
        name: 'reception',
        component: () => import('@/views/reception/index'),
        meta: { title: '业务受理', icon: 'list', permission: ['reception_index'] }
      },
      {
        hidden: true,
        path: 'collect',
        name: 'collect',
        component: () => import('@/views/reception/collect/index'),
        meta: { title: '受理资料', icon: 'list', permission: ['reception_collect'] }
      }
    ]
  },
  {
    path: '/temporary',
    component: Layout,
    meta: { title: '我的暂存', icon: 'list', permission: ['temporary_index'] },
    children: [
      {
        path: '',
        name: 'temporary',
        component: () => import('@/views/temporary/index'),
        meta: { title: '我的暂存', icon: 'list', permission: ['temporary_index'] }
      }
    ]
  },
  {
    path: '/approval',
    component: Layout,
    meta: { title: '我的待办', icon: 'list', permission: ['approval_wait'] },
    children: [
      {
        path: 'wait',
        name: 'wait',
        props: () => ({ pageKey: 'wait' }),
        component: () => import('@/views/approval/index'),
        meta: { title: '我的待办', icon: 'list', permission: ['approval_wait'] }
      },
      {
        hidden: true,
        path: 'accept-audit',
        name: 'acceptAudit',
        props: () => ({ pageKey: 'wait' }),
        component: () => import('@/views/approval/audit'),
        meta: { title: '立即受理', permission: ['approval_audit'] }
      }
    ]
  },
  {
    path: '/approval',
    component: Layout,
    meta: { permission: ['approval', 'approval_joined'] },
    children: [
      {
        path: 'joined',
        name: 'joined',
        props: () => ({ pageKey: 'joined' }),
        component: () => import('@/views/approval/index'),
        meta: { title: '我的经办', icon: 'list', permission: ['approval_joined'] }
      },
      {
        hidden: true,
        path: 'view',
        name: 'approvalInfo',
        component: () => import('@/views/approval/audit'),
        meta: { title: '查看详情', noCache: true, permission: ['approval_audit'] }
      }
    ]
  },
  {
    path: '/business-query',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    meta: { permission: ['businessQuery_livingAllowances', 'businessQuery_livingAllowancesChange', 'businessQuery_educationalSupport'], title: '业务信息查询', icon: 'eye' },
    name: 'businessQuery',
    children: [
      {
        path: 'living-allowances/city',
        name: 'queryLivingAllowancesCity',
        props: () => ({ approvalKey: 'LIVING_ALLOWANCES' }),
        component: () => import('@/views/businessQuery/livingAllowances/index'),
        meta: {
          title: '城市低保', icon: 'list',
          permission: ['businessQuery_livingAllowances']
        }
      },
      {
        path: 'living-allowances/country',
        name: 'queryLivingAllowancesCountry',
        props: () => ({ approvalKey: 'LIVING_ALLOWANCES_AGRICULTURAL' }),
        component: () => import('@/views/businessQuery/livingAllowances/index'),
        meta: {
          title: '农村低保', icon: 'list',
          permission: ['businessQuery_livingAllowances']
        }
      },
      {
        hidden: true,
        path: 'living-allowances/change',
        name: 'queryLivingAllowancesChange',
        component: () => import('@/views/businessQuery/livingAllowances/change'),
        meta: {
          title: '低保详情', icon: 'list',
          permission: ['businessQuery_livingAllowancesChange']
        }
      },
      {
        path: 'educational-support',
        name: 'queryEducationalSupport',
        component: () => import('@/views/businessQuery/educationalSupport/index'),
        meta: {
          title: '教育救助', icon: 'list',
          permission: ['businessQuery_educationalSupport']
        }
      }
    ]
  },
  {
    path: '/statistical',
    component: Layout,
    alwaysShow: true,
    name: 'statistical',
    redirect: 'noredirect',
    meta: { permission: ['statistical_Index', 'statistical_civil_Index', 'statistical_civil_la_Index', 'statistical_civil_es_Index'], title: '统计管理', icon: 'chart' },
    children: [
      {
        path: '/statistical/civil',
        name: 'civil',
        alwaysShow: true,
        component: () => import('@/views/statistical/civil/index'),
        redirect: 'noredirect',
        meta: {
          title: '民政业务',
          permission: ['statistical_civil_Index']
        },
        children: [
          {
            path: 'living-allowances/city',
            name: 'statisticalLaCity',
            props: () => ({ approvalKey: 'LIVING_ALLOWANCES' }),
            component: () => import('@/views/statistical/civil/livingAllowances/index'),
            meta: {
              title: '城市低保', icon: 'list',
              permission: ['statistical_civil_la_Index']
            }
          },
          {
            path: 'living-allowances/country',
            name: 'statisticalLaCountry',
            props: () => ({ approvalKey: 'LIVING_ALLOWANCES_AGRICULTURAL' }),
            component: () => import('@/views/statistical/civil/livingAllowances/index'),
            meta: {
              title: '农村低保', icon: 'list',
              permission: ['statistical_civil_la_Index']
            }
          },
          {
            path: 'educational-support',
            name: 'statisticalEs',
            component: () => import('@/views/statistical/civil/educationalSupport/index'),
            meta: {
              title: '教育救助',
              icon: 'list',
              permission: ['statistical_civil_es_Index']
            }
          }
        ]
      }
    ]
  },
  {
    path: '/personal-query',
    component: Layout,
    redirct: '/personal-query',
    meta: { permission: ['personalQuery_Index', 'personalQuery_Index_Result'] },
    children: [
      {
        path: '',
        name: 'personalQuery',
        component: () => import('@/views/personalQuery/index'),
        meta: {
          title: '个人信息查询',
          icon: 'list',
          permission: ['personalQuery_Index']
        }
      },
      {
        hidden: true,
        path: 'result',
        name: 'personalQueryResult',
        component: () => import('@/views/personalQuery/result'),
        meta: {
          title: '个人信息查询结果',
          icon: 'list',
          permission: ['personalQuery_Index_Result']
        }
      }
    ]
  },
  {
    path: '/system',
    component: Layout,
    name: 'systemMgr',
    alwaysShow: true,
    redirect: '/system/user',
    meta: { icon: 'component', permission: ['system_user', 'system_resources', 'system_role', 'system_dept', 'system_workflow'], title: '系统管理' },
    children: [
      {
        path: 'user',
        component: () => import('@/views/system/user/index'),
        name: 'userMgr',
        meta: { title: '用户管理', icon: 'peoples', permission: ['system_user'] }
      },
      {
        path: 'resources',
        component: () => import('@/views/system/resources/index'),
        name: 'resourcesMgr',
        meta: { title: '菜单管理', icon: 'list', permission: ['system_resources'] }
      },
      {
        path: 'role',
        component: () => import('@/views/system/role/index'),
        name: 'roleMgr',
        meta: { title: '角色管理', icon: 'people', permission: ['system_role'] }
      },
      {
        path: 'dept',
        component: () => import('@/views/system/detp/index'),
        name: 'detpMgr',
        meta: { title: '组织机构', icon: 'list', permission: ['system_dept'] }
      },
      {
        path: 'workflow',
        component: () => import('@/views/system/workflow/index'),
        name: 'workflow',
        meta: { title: '流程配置', icon: 'list', permission: ['system_workflow'] }
      },
      {
        name: 'dict',
        path: 'dict',
        component: _import('system/dict/index'),
        meta: { title: '字典', icon: 'dashboard', noCache: true }
      }
    ]
  },
  {
    path: '/money',
    component: Layout,
    meta: { permission: ['money', 'money_money'] , title: '资金管理', icon: 'money' },
    children: [
      {
        path: 'year',
        name: 'yearData',
        component: () => import('@/views/money/index'),
        meta: { title: '资金拨款', noCache: true, permission: ['money_money'] }
      },
      {
        path: 'detail',
        name: 'detailData',
        component: () => import('@/views/money/detail'),
        meta: { title: '拨款查询', noCache: true, permission: ['money_money'] }
      }
    ]
  },
  {
    path: '/news',
    component: Layout,
    redirect: '/news/',
    meta: { permission: ['news', 'news_news'] },
    children: [
      {
        path: 'new',
        name: 'new',
        component: () => import('@/views/news/index'),
        meta: { title: '新闻管理', icon: 'list', permission: ['news_news'] }
      },
      {
        hidden: true,
        path: 'newdetail',
        name: 'newdetails',
        component: () => import('@/views/news/details'),
        meta: { title: '新闻详情', noCache: true, permission: ['news_news'] }
      }
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
];
